In this video we are going to plot the data on our Titanic data frame with the method plot.
But first of all let's import pandas and we import our Titanic data set.
So here are the first five rows and some meta information.
And if you want to create some plots and visualizations we first need to import the map plot lip library
which is actually the most popular python library for creating plots and visualizations and actually
as convention we import mad plot lip dubbed pi plot SBT.
So a penalty is actually the most commonly used the previous Asian here.
So let's do this.
Now we want to plot to the numerical columns in our Titanic data frame.
So we have some numerical columns here.
We have this advice column the peak class column the H column space P parts and also the fact column
and we can do this by simply calling here the plot method on our Titanic data frame so far Pena's data
frames and pandas the areas that is the built and method the dot plot.
And before we run the set here we have to also call the show method.
So.
So this is a direct map plot laptop type love method.
And with that the show method we can actually display our graph our plot.
So all of a sudden we create one or several plots of asylum and plug lip as the very last argument we
have to call here the show method.
So let's simply call here the plot method on our entire Titanic data frame and that's from the set here
and here we can see that we actually see nothing.
So by default the plot method creates here a line plot with on the x axis then the index.
So here we have the range index from zero to eight hundred ninety one.
So these are actually the passenger numbers and on the y axis we have actually these specific values
and our numerical columns and for each column we have actually here a line plot.
So we have six columns here and as we have here a six line plots more than one graph within one plot.
That's quite hard to see anything and therefore let's go here inside the brackets.
Let's shift tab.
And here we can see we have a pair of meta subplots and by default it's set to forwards but we can set
this also to true here
and by doing so we're creating for each column a separate subplot.
And still it's hard to see anything because the plot size is very small and that's an additional parameter
here.
And it's called the fixed size and we can determine the width and the height of the graph.
So let's do this here.
We have here fixed size and then we have to pass the then a top of the desired the width and the height
of the graph.
So for example you want to f a bit of twelve and a height of eight
then we get to a larger plot and maybe you should further increase the size here to maybe 15 month 12
of.
So now it's much easier to see and analyze it.
So for each column we have a separate subplot.
So you have for the survival column the plus column the H column the best B column patch column and
fact column.
And by default all the subplots share actually.
The x axis.
So we have here at the very bottom one x axis the width of the Range Index from zero to eight hundred
ninety one.
But we can also create a separate x axis for each subplot.
And that is the one parameter here and the parameter yes share X. So let's have a look here and by default
it's set to true actually.
So all subplots share one x axis but we can also set this to form.
So let's do this.
So we have these share experiments and we can set it to fours and we can see here at the bottom of each
subplot.
The x axis with the arranged index from 0 to 891 and we can see on the left hand side for each subplot
actually the y axis.
And here we have a specific y axis.
For each subplot.
So for example here if this survives column we have values between 0 and 1.
So you can see here it's isolating between 0 and 1 then here for the peak class column we have the values
1 2 and 3 then for the H column we have values between 0 and 80 and the line plot like this is actually
good to see in the distribution of values.
So the majority of ages are yeah between 20 and 40.
But we have some outliers here around zero and some outliers around the 75 80.
And specifically when we have time serious data with a daytime index.
So we have been on the x axis a daytime index.
So for example starting from the year 2010 onto two thousand and fifteen and specifically in this case
a line plot is very intuitive to see the evolution of some factors over time.
So for example stock prices or weather data but also you have a non time serious data a line plot to
the max.
That definitely sentence and here in this FSP column we can see that the majority of fair use are here
actually 1.
So most of the passengers have one sibling or spouse onboard.
And also you have for the parents and children the most frequent values are between 0 and 2 and also
you in the fact column we can see that the most frequent fast are actually quite low year between 0
and 20.
However there are some outliers here.
So we have some outliers onto four or five hundred dollars and we have seen on the left hand side so
fights subplot.
We have a different scale for the y axis but we can also change this year.
So yes that apparently does share y
so we have Y
and by default it's set to fall so far a subplot.
We have a specific and appropriate y axis but we can also set this to a true
a..
For a subplot.
Actually these same y axis with the same scale.
And as we have here the largest scale at the fact column.
So the sad y axis is actually most appropriate here for the fact column.
So here we have values between zero and 500.
However for the patch column a scale between zero and five hundred does not really make sense.
So here we actually see nothing.
And therefore in this case that definitely makes sense to set these shall y Wyatt parameter to fours
and actually if you are only interested in the H column and if you only want to visualize that the H
column you can also apply the plot method only on the H column so let's do this let's copy the code
and instead of using the plot method on the entire Titanic that afraid to use it only on the H column
and if you only use it on the edge column we do not have to define me as subplots.
So this is not necessary and maybe we make the figure a size a bit smaller here because we have only
one subplot.
And also we do not need to do apparently does share X and shall y so let's plotted the graph.
And here we have actually a line plot only for the H column so we can't see the x axis that the index
letters from 0 to 890 is.
And we can see on the by axis values between zero and 80 and the majority of fair use are here between
20 and 40 and we have some very young passengers that are only a bit older than the serial Yes loads
so babies and we have some quite old peasants as above 70 and until 80.
All right.
This was the first video on data visualization and in the next video we learn how to customize our plot
here.
So I hope to see you there by.